// app/controller/cross_organization_analysis_controller.js
'use strict';

const { Controller } = require('egg');
const CrossOrganizationAnalysisService = require('../service/cross_organization_analysis_service');

class CrossOrganizationAnalysisController extends Controller {
  // 获取跨组织客户分析数据
  async getCustomerAnalysis() {
    const { ctx } = this;
    
    try {
      const analysisService = new CrossOrganizationAnalysisService(ctx);
      const result = await analysisService.getCrossOrganizationCustomerAnalysis();
      
      ctx.success(result);
    } catch (error) {
      ctx.logger.error('获取跨组织客户分析数据失败:', error);
      ctx.error(`获取跨组织客户分析数据失败: ${error.message}`);
    }
  }
  
  // 获取跨组织销售分析数据
  async getSalesAnalysis() {
    const { ctx } = this;
    
    try {
      const analysisService = new CrossOrganizationAnalysisService(ctx);
      const result = await analysisService.getCrossOrganizationSalesAnalysis();
      
      ctx.success(result);
    } catch (error) {
      ctx.logger.error('获取跨组织销售分析数据失败:', error);
      ctx.error(`获取跨组织销售分析数据失败: ${error.message}`);
    }
  }
  
  // 获取跨组织财务分析数据
  async getFinancialAnalysis() {
    const { ctx } = this;
    
    try {
      const analysisService = new CrossOrganizationAnalysisService(ctx);
      const result = await analysisService.getCrossOrganizationFinancialAnalysis();
      
      ctx.success(result);
    } catch (error) {
      ctx.logger.error('获取跨组织财务分析数据失败:', error);
      ctx.error(`获取跨组织财务分析数据失败: ${error.message}`);
    }
  }
  
  // 获取跨组织供应商分析数据
  async getSupplierAnalysis() {
    const { ctx } = this;
    
    try {
      const analysisService = new CrossOrganizationAnalysisService(ctx);
      const result = await analysisService.getCrossOrganizationSupplierAnalysis();
      
      ctx.success(result);
    } catch (error) {
      ctx.logger.error('获取跨组织供应商分析数据失败:', error);
      ctx.error(`获取跨组织供应商分析数据失败: ${error.message}`);
    }
  }
}

module.exports = CrossOrganizationAnalysisController;